﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Dynamic;

namespace Eleanor.DAL
{
    public class CatalogDAL : DALBase
    {
        public dynamic CustomMapperUsingDynamic(dynamic row)
        {
            if (row == null)
            {
                return null;
            }
            dynamic catalog = new ExpandoObject();
            catalog.CatalogId = row.catalog_id;
            catalog.Name = row.name;
            catalog.Description = row.description;
            catalog.CreateDate = row.create_date;
            catalog.UpdateDate = row.update_date;
            catalog.SmallOrderDescription = row.small_order_description;
            catalog.BulkOrderDescription = row.bulk_order_description;
            return catalog;
        }


        public dynamic Select(string catalogName)
        {
            const string sql = @"select * from catalog where name=@0";
            return CustomMapperUsingDynamic(DefaultContext.Sql(sql).Parameters(catalogName).QuerySingle<dynamic>());
        }
    }
}
